//package com.company.mapper.impl;
//
//import com.company.Utils.MyBatisUtils;
//import com.company.bean.Student;
//import com.company.mapper.StudentMapper;
//import org.apache.ibatis.io.Resources;
//import org.apache.ibatis.session.SqlSession;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.apache.ibatis.session.SqlSessionFactoryBuilder;
//
//import javax.annotation.Resource;
//import java.io.IOException;
//import java.io.InputStream;
//import java.util.List;
//
//public class StudentMapperImp implements StudentMapper {
//    @Override
//    public List<Student> selectAll() {
////        List<Student> list = null;
////        InputStream is = null;
////        SqlSession sqlSession = null;
////        try {
////            is = Resources.getResourceAsStream("MyBatisConfig.xml");
////            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
////            sqlSession = sqlSessionFactory.openSession();
////            list = sqlSession.selectList("StudentMapper.selectAll");
////
////        } catch (IOException e) {
////            e.printStackTrace();
////        }finally {
////            if (is != null) {
////                try {
////                    is.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
////        }
////        if (sqlSession != null) {
////            try {
////                sqlSession.close();
////            } catch (Exception e) {
////                e.printStackTrace();
////            }
////        }
//        SqlSession sqlSession = MyBatisUtils.getSqlSession();
//        List<Student> list = sqlSession.selectList("StudentMapper.selectAll");
//        sqlSession.close();
//        return list;
//    }
//
//    @Override
//    public Student selectByid(Integer id) {
////
//        SqlSession sqlSession = MyBatisUtils.getSqlSession();
//        Student stu = sqlSession.selectOne("StudentMapper.selectByid", id);
//        sqlSession.close();
//
//        return stu;
//    }
//
//    @Override
//    public Integer insert(Student student) {
////        InputStream is = null;
////        int insert = 0;
////        SqlSession sqlSession=null;
////        try {
////            is = Resources.getResourceAsStream("MyBatisConfig.xml");
////            SqlSessionFactory build = new SqlSessionFactoryBuilder().build(is);
////             sqlSession = build.openSession();
////            insert = sqlSession.insert("StudentMapper.insert", student);
////            sqlSession.commit();
////            sqlSession.close();
////        } catch (IOException e) {
////            e.printStackTrace();
////        }finally {
////            if (is != null) {
////                try {
////                    is.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
////            if (sqlSession != null) {
////                try {
////                    sqlSession.close();
////                } catch (Exception e) {
////                    e.printStackTrace();
////                }
////
////            }
////        }
//        SqlSession sqlSession = MyBatisUtils.getSqlSession();
//        int insert = sqlSession.insert("StudentMapper.insert", student);
//        sqlSession.close();
//        return insert;
//
//    }
//
//    @Override
//    public Integer update(Student student) {
////        InputStream is = null;
////        SqlSession sqlSession=null;
////        int update =0;
////        try {
////            is = Resources.getResourceAsStream("MyBatisConfig.xml");
////            SqlSessionFactory build = new SqlSessionFactoryBuilder().build(is);
////            sqlSession = build.openSession();
////            update = sqlSession.update("StudentMapper.update", student);
////            sqlSession.commit();
////            sqlSession.close();
////        } catch (IOException e) {
////            e.printStackTrace();
////        }finally {
////            if (is != null) {
////                try {
////                    is.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
////            if (sqlSession != null) {
////                try {
////                    sqlSession.close();
////                } catch (Exception e) {
////                    e.printStackTrace();
////                }
////
////            }
////        }
//        SqlSession sqlSession = MyBatisUtils.getSqlSession();
//        int update = sqlSession.update("StudentMapper.update", student);
//        sqlSession.close();
//        return update;
//    }
//
//    @Override
//    public Integer delete(Integer id) {
////        InputStream is =null;
////        int delete=0;
////        SqlSession sqlSession = null;
////        try {
////            is = Resources.getResourceAsStream("MyBatisConfig.xml");
////            SqlSessionFactory build = new SqlSessionFactoryBuilder().build(is);
////            sqlSession = build.openSession();
////            delete = sqlSession.delete("StudentMapper.delete", id);
////            sqlSession.commit();
////            sqlSession.close();
////        } catch (IOException e) {
////            e.printStackTrace();
////        }finally {
////            if (is != null) {
////                try {
////                    is.close();
////                } catch (IOException e) {
////                    e.printStackTrace();
////                }
////            }
////            if (sqlSession != null) {
////                try {
////                    sqlSession.close();
////                } catch (Exception e) {
////                    e.printStackTrace();
////                }
////
////            }
////
////        }
//        SqlSession sqlSession = MyBatisUtils.getSqlSession();
//        int delete = sqlSession.delete("StudentMapper.delete", id);
//        sqlSession.close();
//        return delete;
//    }
//}
